package com.yanyu.space.common.auth.support;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.beans.factory.support.GenericBeanDefinition;

/**
 * @author yanyu
 */
public class SaTokenBeanFactoryPostProcessor implements BeanDefinitionRegistryPostProcessor {

    /**
     * 移除SaBeanRegister类中现有逻辑
     */
    private static final String REMOVEBEAN = "getSaTokenConfig";

    @Override
    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry beanDefinitionRegistry) throws BeansException {
        if (beanDefinitionRegistry.containsBeanDefinition(REMOVEBEAN)) {
            beanDefinitionRegistry.removeBeanDefinition(REMOVEBEAN);
            GenericBeanDefinition gbdefinition = new GenericBeanDefinition();
            gbdefinition.setBeanClass(SaTokensPropoerties.class);
            beanDefinitionRegistry.registerBeanDefinition(SaTokensPropoerties.class.getName(), gbdefinition);
        }

    }

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {
    }
}
